home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 298 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  51 lines

  1. Path: news.nacm.com!usenet
  2. From: brandon@criterion.com (Brandon Wallace)
  3. Newsgroups: comp.lang.c++,comp.lang.fortran
  4. Subject: Re: coupling c++ code with fortran
  5. Date: 3 Jan 1996 16:23:33 GMT
  6. Organization: Nicholas|Applegate Capital Management, San Diego, CA
  7. Message-ID: <4ceai5$2oa@news.nacm.com>
  8. References: <4ce0sp$ddv@fontainebleau.ensmp.fr>
  9. NNTP-Posting-Host: 204.255.80.4
  10. X-Newsreader: knews 0.9.2
  11. In-Reply-To: <4ce0sp$ddv@fontainebleau.ensmp.fr>
  12. To: salignac@cig.ensmp.fr
  13.  
  14. In article <4ce0sp$ddv@fontainebleau.ensmp.fr>,
  15.     salignac@cig.ensmp.fr writes:
  16. -> Hello !
  17. -> 
  18. -> I'm trying to call a C++ subroutine in a Fortran 77 code.
  19. -> The compilation fails while linking: it seems impossible
  20. -> for the fortran compiler/linker to recognize the C++ function.
  21. -> In plain C, the problem is easily solved by adding underscores 
  22. -> at the start of the C-function name, but this is clearly
  23. -> different for C++....
  24. -> 
  25. -> Does anyone know which syntax is recognized by both compilers?
  26. -> Are there examples available ?
  27. -> 
  28. -> I currently use the gnu-C++ compiler (v.2.7.0) and the standard
  29. -> Unix f77 compiler. Trials with the gnu-f77 compiler failed
  30. -> for the same reason.
  31. -> Answers by e-mail would be most appreciated.
  32.  
  33. Declare your C++ function extern "C"...as
  34.  
  35. extern "C" void callablefromfortran_ (void);
  36.  
  37. Also, be aware that problems can occur if you use anything
  38. like the iostreams package.  You will get things like
  39. bus-errors.  You should really have a C++ main 
  40. which includes <iostream.h>, and it should call your
  41. FORTRAN function, which then can go and call your C++
  42. function, etc...Then you should link with the g++, and
  43. make sure and include the fortran libraries (with the
  44. sparccompiler, they are -lF77 -lM77 -lm).
  45. -- 
  46.                       Brandon Wallace
  47.             Nicholas | Applegate Capital Management
  48. mailto:bman@criterion.com  http://www.criterion.com/home-pages/brandon
  49.           "I live life face down in the fast lane."
  50.  
  51.